import { toauditList, auditDetail, submit } from '@/api/approve'

const state = {
  todolist: [],
  detail: null,
  total: 0
}

const mutations = {
  SET_TODO_LIST: (state, list) => {
    state.todolist = list
  },
  SET_DETAIL: (state, detail) => {
    state.detail = detail
  },
  SET_TOTAL: (state, total) => {
    state.total = total
  }
}

const actions = {
  async fetchToDoList({ commit }, payload) {
    const data = await toauditList(payload)
    const list = data && data.records || []
    const total = data && data.total || 0
    commit('SET_TODO_LIST', list)
    commit('SET_TOTAL', total)
  },
  async fetchDetail({ commit }, excelId) {
    const data = await auditDetail(excelId)
    commit('SET_DETAIL', data)
  },
  async submit({ commit }, { excelId, status, remark, data }) {
    return await submit({ excelId, status, remark }, data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
